﻿//根据url查询字符串中的参数获取值
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return (r[2]); return null;
}
//去除头尾的空格
String.prototype.trim=function() {  
    return this.replace(/(^\s*)|(\s*$)/g,'');  
};
//示例：String.format("大家好我是%1,我来自%2","郭靖","桃花岛")
String.format = function(str) {
	var args = arguments;
	var re = new RegExp("%([1-" + args.length + "])", "g");
	return String(str).replace(
		re,
		function($1, $2) {
			return args[$2];
		}
	);
};
//格式可以为："yyyy-MM-dd hh:mm:ss"
//示例:new Date().format("yyyy-MM-dd");
Date.prototype.format = function(format){ 
    var o = { 
		"M+" : this.getMonth()+1, //month 
		"d+" : this.getDate(), //day 
		"h+" : this.getHours(), //hour 
		"m+" : this.getMinutes(), //minute 
		"s+" : this.getSeconds(), //second 
		"q+" : Math.floor((this.getMonth()+3)/3), //quarter 
		"S" : this.getMilliseconds() //millisecond 
    } 
    if(/(y+)/.test(format)) { 
		format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
    }
    for(var k in o) { 
		if(new RegExp("("+ k +")").test(format)) { 
			format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length)); 
		} 
    } 
    return format; 
}